$NG.AllReady(function (
    page,
    {
        useValuesChange,
        useClick,
        useUpdateRow,
        useUpdateRows,
        useDataIndexChange,
        useBeforeClick,
    }
) {
    var issueMap = {}
    var mstform = $NG.getCmpApi("p_form_suppy_deter_m");
    var dgrid1 = $NG.getCmpApi("p_form_suppy_deter_d1");

    var gridTab = $NG.getCmpApi("p_form_suppy_deter_d2"); // 获取tab页数据
    var gridTab4 = $NG.getCmpApi("p_form_suppy_deter_d4"); // 获取tab页数据
    // var ShopView = $NG.getCmpApi("p_form_suppy_deter_d6"); // 采购视图
    // var GYSXXTAB = $NG.getCmpApi("p_form_suppy_deter_d5"); // 供应商信息
    // $NG.getCmpApi("toolbar_p_form_suppy_deter_d1").getItem("imp").setHiddn();
    $NG.getCmpApi("toolbar_p_form_suppy_deter_d4").getItem("imp").setHidden();
    $NG.getCmpApi("toolbar_p_form_suppy_deter_d1").getItem("attachment").setHidden();
    $NG.getCmpApi("toolbar_p_form_suppy_deter_d2").getItem("attachment").setHidden();
    $NG.getCmpApi("toolbar_p_form_suppy_deter_d3").getItem("attachment").setHidden();
    $NG.getCmpApi("toolbar_p_form_suppy_deter_d4").getItem("attachment").setHidden();
    const toolbar_dgrid = $NG.getCmpApi("toolbar_p_form_suppy_deter_d2");
    toolbar_dgrid.insert({
        id: "getXl",
        text: "获取小类",
        iconCls: "icon-InsertRow",
    });
    const toolbar = $NG.getCmpApi("toolbar_top");
    toolbar.getItem("imp").setProps({ children: "引用供应商信息" });
    let GYScompno = ""; //供应商编号
    localStorage.setItem("GYScompno", JSON.stringify(""));
    var Flag1; //判断是否满足设备物资通用性条件
    const getItemValue = (itemName) => {
        try{
            return mstform.getItem(itemName).getValue()
        }catch(err){
            return undefined
        }
    };
    {
        //初始化逻辑BEGIN
        try{
            if ($NG.getCmpApi("p_form_suppy_deter_m").getItem("phid_pc").getValue()) {
            getPtInfoByPhid();
        }
        }catch(err){}
    } //初始化逻辑END

    {
        //表头字段变化逻辑BEGIN
        useValuesChange(({ args }) => {
            getPtInfoByPhid();
        }, "p_form_suppy_deter_m.phid_pc");
    } //表头字段变化逻辑END
    if (page.oType == 'add') {   
        // 币种默认为人民币
        mstform.getItem("u_mrbz").setValue({         
         value: 1,
         label: "人民币",
        });
    }
    //获取小类
    useClick(async function ({ args }) {
        let rows = gridTab.getRows()
        const gfid = mstform.getItem("u_supply_name").getValue();
        console.log(gfid);
        
        if (gfid) {
            $NG.external.openNGHelp({
                type: "NGMultipleHelp",
                helpId: "GETsupply_resbs",
                valueField: "fg3_supplyitemfile.phid",
                labelField: "res_bs.name",
                clientSqlFilter:
                    "fg3_supplyitemfile.phid_ent = " + gfid,
            }).then((data) => {
                //根据字段名称新增引入每一行
                console.log(data, "data111111");
                try {
                    if (Array.isArray(data) && data.length > 0) {
                        var gridArr = [];
                        for (var i = 0; i < data.length; i++) {
                            console.log(data[i], "row1数据");
                            var gridObj = {};
                            gridObj.u_wzxl = data[i].origin.phid_res; 
                            gridObj.u_wzxl_EXName = data[i].origin.Name; //单位名称;
    
                            gridArr.push(gridObj);
                        }
    
                        console.log("planadd gridArr:");
                        console.log(gridArr);
                        gridTab.addRows(gridArr);
                        gridTab.refreshView();
                    } else {
                        console.error("返回的数据无效或为空:", data);
                    }
                } catch (error) {
                    console.error("处理数据时出错:", error);
                }
            })
        }else{
            $NG.alert("请先填写供方名称")
        }

    }, "getXl");

    //监听合同名称变化
    useValuesChange(({ args }) => {
        console.log(args[0].u_cnt.origin.bill_no, "argsqqqqqqqqqqqqq");
        $NG.updateState((updater) => {
            updater.data.p_form_suppy_deter_m.setProps({
                u_cnt_no: {
                    label: args[0].u_cnt.origin.bill_no,
                    value: args[0].u_cnt.origin.bill_no,
                },
            });

        });
    }, "p_form_suppy_deter_m.u_cnt");
    // $NG.updateUI((updater, state) => {
    //     console.log('过滤参数检查', updater);
    //     updater.fieldSetForm.p_form_suppy_deter_m.u_supply_name.setProps({
    //         onBeforeOpen: async () => {
    //             var phid_pc = $NG.getCmpApi('p_form_suppy_deter_m').getItem('u_is_gfxz').getValue();
    //             if (!phid_pc) {
    //                 $NG.alert("请先选择是否新增供应商");
    //                 return false;
    //             } else {
    //                 return true;
    //             }
    //         },
    //     });
    // });
    useValuesChange(({ args }) => {
        console.log(mstform.getItem('u_is_gfxz').getValue(),123);
      if (mstform.getItem('u_is_gfxz').getValue() == 1) {
        $NG.updateUI((updater, state) => {
            console.log('过滤参数检查', updater);
            updater.fieldSetForm.p_form_suppy_deter_m.u_supply_name.setProps({
                // onBeforeOpen: () => {
                //     var phid_pc = $NG.getCmpApi('p_form_suppy_deter_m').getItem('u_is_gfxz').getValue();
                //     if (!phid_pc) {
                //         $NG.alert("请先选择是否新增供应商");
                //         return false;
                //     } else {
                //         return true;
                //     }
                // },
             
					clientSqlFilter: {
                        'fg3_supplyfile.user_rdxx':'1'
                    }
				
                    // clientSqlFilter: `fg3_supplyfile.user_rdxx = 1`
            });
        });
      }
    }, "p_form_suppy_deter_m.u_is_gfxz");
    useUpdateRow(({args})=>{
        $NG.execServer("getGysrdCw",{phid:args[0].u_bank_kh},(res)=>{
            console.log(`测试`,res);
            if(res.count == 0) return 
            const _data = JSON.parse(res.data)[0].extendObjects
            args[0].u_lhh = _data.bankno
            dgrid1.refreshView()
        })
        dgrid1.refreshView()
    },"p_form_suppy_deter_d1")
    useValuesChange(({args})=>{
        console.log(`国家`,args[0],args[0].u_nation.origin);
        $NG.updateUI((updater, state) => {
            console.log('过滤参数检查', updater);
            updater.fieldSetForm.p_form_suppy_deter_m.u_province.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_suppy_deter_m').getItem('u_nation').getValue();
                    if (!phid_pc) {
                        $NG.alert("请先选择国家");
                        return false;
                    } else {
                        return true;
                    }
                },
                ...{
                    clientSqlFilter: {
                        nationid:Number(args[0].u_nation.origin.nationno)
                    }
                },
            });
        });
    },"p_form_suppy_deter_m.u_nation")
    //监听省份变化
    useValuesChange(({ args }) => {
        console.log(args, "监听省份变化");
        $NG.updateUI((updater, state) => {
            console.log('过滤参数检查', updater);
            updater.fieldSetForm.p_form_suppy_deter_m.u_city.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_suppy_deter_m').getItem('u_province').getValue();
                    if (!phid_pc) {
                        $NG.alert("请先选择省份");
                        return false;
                    } else {
                        return true;
                    }
                },
                ...(!!$NG.getCmpApi('p_form_suppy_deter_m').getItem('u_province').getValue() && {
                    clientSqlFilter: {
                        provinceno:mstform.getItem("u_province").getValue()
                    }
                }),
            });
        });
    }, "p_form_suppy_deter_m.u_province");
    
    useValuesChange(({ args }) => {
        console.log(args, "监听省份变化");
        $NG.updateUI((updater, state) => {
            console.log('过滤参数检查', updater);
            updater.fieldSetForm.p_form_suppy_deter_m.u_extend_region.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_suppy_deter_m').getItem('u_province').getValue();
                    if (!phid_pc) {
                        $NG.alert("请先选择省份");
                        return false;
                    } else {
                        return true;
                    }
                },
                ...(!!$NG.getCmpApi('p_form_suppy_deter_m').getItem('u_province').getValue() && {
                    clientSqlFilter: {
                        cityno:mstform.getItem("u_city").getValue()
                    }
                }),
            });
        });
    }, "p_form_suppy_deter_m.u_city");

    /**
     *@license: 检测合同时间判断是否符合要求
     */

    /**
     *@license: 采购视图数据变化
     */
    useUpdateRows(({ args }) => {
        args[0].forEach((item) => {
            if (mstform.getItem("phid_org").getValue()) {
                item.u_cgorg = mstform.getItem("phid_org").getValue();
                $NG.execServer(
                    "getOrgWithId",
                    {
                        phid: mstform.getItem("phid_org").getValue(),
                    },
                    function (res) {
                        const Oname = JSON.parse(res.data)[0].extendObjects.oname;
                        console.log(Oname, "Oname");
                        item.u_cgorg_EXName = Oname;
                        // ShopView.refreshView();
                    }
                );
            }
            // ShopView.refreshView();
        });
    }, "p_form_suppy_deter_d6");
    /**
     *@license: 供应商信息
     */
    useUpdateRows(({ args }) => {
        console.log(JSON.parse(localStorage.getItem("GYScompno")), "GYScompno");

        args[0].forEach((item) => {
            item.u_gysbm = JSON.parse(localStorage.getItem("GYScompno"));
            // GYSXXTAB.refreshView();
        });
    }, "p_form_suppy_deter_d5");

    /**
     *@license: 监听案例情况表 1.累计案情数量
     */

    useUpdateRows(({ args }) => {
        console.log(args, "p_form_suppy_deter_d4");
        reduceTable2(args[0]);
    }, "p_form_suppy_deter_d4");
    /**
     *@license: 检测合同时间判断是否符合要求
     */

    // useUpdateRow(({ args }) => {
    //     let row = args[0];
    //     console.log(row, "时间");
    //     if (row.u_cnt_dt) {
    //         let timeFlag = isWithinYears(row?.u_cnt_dt, 2);
    //         if (!timeFlag) {
                
    //             args[0].u_cnt_dt = null;
    //             gridTab4.updateRow(args[0]);
    //             gridTab4.refreshView();
    //             return false;
    //         }
    //     }
    // }, "p_form_suppy_deter_d4");

    /**
     *@license:监听设备通用性 判断是否符合要求
     */
    useValuesChange(({ args }) => {
        console.log(args[0].u_sbwztyx.origin.value, "sbwztyx");
        let sbwztyxVal = getItemValue("u_sbwztyx");
        let AlNum = gridTab4.getRows().length; //累计案情数量
        console.log(AlNum, sbwztyxVal, "累计案情数量");
        pdFun(AlNum, sbwztyxVal);
        // ("通用集成产品1");3
        // ("专用集成产品");2
        // ("新扩展业务涉及设备行业应用");2
    }, "p_form_suppy_deter_m.u_sbwztyx");
//////
useValuesChange(({args})=>{
    if(args[0].u_is_ssgs?.key != 1){
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_ssgsdm.setProps({
                disabled: true, //只读
            });
            mstform.getItem("u_ssgsdm").setValue('');
        });
    }else{
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_ssgsdm.setProps({
                disabled: false, //只读
            });
        });
    }
  
},"p_form_suppy_deter_m.u_is_ssgs")
useValuesChange(({args})=>{
    if(args[0].u_is_zzcpdj?.key == 2){
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_is_jksfmz.setProps({
                disabled: true, //只读
            });
            mstform.getItem("u_is_jksfmz").setValue('');
        });
    }else{
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_is_jksfmz.setProps({
                disabled: false, //只读
            });
        });
    }
  
},"p_form_suppy_deter_m.u_is_zzcpdj")
useValuesChange(({args})=>{
    if(args[0].u_is_sqmc?.key == 1){
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_kzcs.setProps({
                disabled: true, //只读
            });
            mstform.getItem("u_kzcs").setValue('');
        });
    }else{
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_kzcs.setProps({
                disabled: false, //只读
            });
        });
    }
  
},"p_form_suppy_deter_m.u_is_sqmc")
useValuesChange(({args})=>{
    if(args[0].u_is_jxcs?.key == 2){
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_is_cswc.setProps({
                disabled: true, //只读
            });
            mstform.getItem("u_is_cswc").setValue('');
        });
    }else{
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_is_cswc.setProps({
                disabled: false, //只读
            });
        });
    }
  
},"p_form_suppy_deter_m.u_is_jxcs")
useValuesChange(({args})=>{
    console.log(args[0].u_sbwztyx?.key);
    if (args[0].u_sbwztyx?.key!= '') {
        mstform.getItem("u_alpg").setValue({
            value: 2,
            label: "有同类案例",
           });
    }else{
        mstform.getItem("u_alpg").setValue({
            value: 0,
            label: "",
           });
    }
},"p_form_suppy_deter_m.u_sbwztyx")

//////
    useValuesChange(({ args }) => {
        //监听供方名称变化
        console.log(args, "argsqqqargs");
        console.log(args[0].u_supply_name.origin.compno, "argsqqqargs");
        // const GYSXXTABRows = GYSXXTAB.getRows();
        // if (args[0].u_supply_name.origin.compno) {
        //     GYSXXTABRows.forEach((item) => {
        //         item.u_gysbm = args[0].u_supply_name.origin.compno;
        //         GYSXXTAB.refreshView();
        //     });
        //     localStorage.setItem(
        //         "GYScompno",
        //         JSON.stringify(args[0].u_supply_name.origin.compno)
        //     );
        // } else {
        //     localStorage.setItem("GYScompno", JSON.stringify(""));
        //     GYSXXTABRows.forEach((item) => {
        //         item.u_gysbm = "";
        //         GYSXXTAB.refreshView();
        //     });
        // }
        // console.log(args[0].u_supply_name.name,11111);
        const name = mstform.getItem("u_supply_name").getText()
        const value = mstform.getItem("u_supply_name").getValue()
        console.log(`name`,name,value);
        setTimeout(()=>{
            console.log(`setTime`,mstform.getItem("u_supply_name").getText());
        },2000)
        $NG.execServer(
            "fbsrdxx",
            { compname: `'${name}'`},
            function (res) {
                if(res.count == 0) return
                const datas = JSON.parse(res.data)[0].extendObjects;
                console.log(datas);

                $NG.updateState((updater) => {
                    updater.data.p_form_suppy_deter_m.setProps({
                        u_name1: datas.compname, //
                        u_contacts: datas.person, //联系人
                        u_contacts_phone: datas.phone, //税务登记电话
                        u_contact_mail: datas.email,
                        u_social_code: datas.unisocialcredit, //社会信用代码11
                        u_person_scale: datas.person_flg, //公司规模11
                        u_legal_db: datas.taxpayername, //法人11
                        u_corporate_id: datas.cardno, //法人身份证身份证
                        u_cl_data: datas.ng_insert_dt, //成立日期11
                        u_register_capital: datas.regmoney, //注册资本11
                        u_zcaddress: datas.address, 
                        u_nation: datas.nation_id, 
                        u_province: datas.province_id, 
                        u_city: datas.city_id, 
                    });
                });
                if (datas.region_id) {
					console.log(datas.region_id, "datas.region_id");
					$NG.execServer("getAddressToId", { phid: datas.region_id }, function (res2) {
						const data2 = JSON.parse(res2.data)[0].extendObjects; //单返回值
						console.log(data2, "data2");
						$NG.updateState((updater) => {
							updater.data.p_form_suppy_deter_m.setProps({
								u_nation: {
									value: data2.nationno,
									label: data2.nationname,
								},
								u_province: {
									value: data2.provinceno,
									label: data2.provincename,
								},
								u_city: {
									value: data2.cityno,
									label: data2.cityname,
								},
								u_extend_region: {
									value: data2.regionno,
									label: data2.regionname,
								},
							});
						});
					});
				}
                if (datas.cardno) {
					$NG.alert(`该法人${datas.taxpayername}已认证过${name}`)
				  }
                  $NG.execServer(
                    "searchGysTt",
                    { phid: mstform.getItem("u_supply_name").getValue() },
                    function (res) {
                        if (res.count == 0) return
                        const datas = JSON.parse(res.data)[0].extendObjects;
                        console.log(datas, "datas");
                        //帮助字段赋值
                        if (datas.user_status == 1||datas.user_status == 2||datas.user_status == 3) {
                            $NG.updateState((updater) => {
                                updater.data.p_form_suppy_deter_m.setProps({
                                    u_is_tcjy: 1,
                                });
                            });
                        }else{
                            $NG.updateState((updater) => {
                                updater.data.p_form_suppy_deter_m.setProps({
                                    u_is_tcjy: 2,
                                });
                            });
                        }
                    }
                );
                if (!datas.iden_card_id) return;
                $NG.execServer(
                    "yrdgysxx",
                    {
                        cardid: datas.iden_card_id,
                    },
                    function (res) {
                        console.log(res, "xxxx111?");
                        let data = JSON.parse(res.data);
                        // console.log(data[0].extendObjects.compno, "datas.compno");

                        console.log(data, "resresres");
                        const removeCompno = (array, compname) => {
                            return array.filter(
                                (item) => item.extendObjects.compname !== compname
                            );
                        };

                        const filteredData = removeCompno(
                            data,
                            name
                        );
                        const compnames = filteredData.map(
                            (item) => item.extendObjects.compname
                        );

                        console.log(compnames, "compnames");
                        if (data.length > 1) {
                            $NG.alert("您认证过其他公司");
                            $NG.alert(compnames);
                        }
                    }
                );
            }
        );
        
    }, "p_form_suppy_deter_m.u_supply_name");
    ////////////////////////////////////////////////////////////////////////////////////

    function getPtInfoByPhid() {
        if (mstform.getItem("phid_pc").getValue()) {
            $NG.execServer(
                "getPtInfoByPhid",
                { phid: mstform.getItem("phid_pc").getValue() },
                function (res) {
                    const datas = JSON.parse(res.data)[0].extendObjects;
                    console.log(datas, "datas");
                    //帮助字段赋值
                    $NG.updateState((updater) => {
                        updater.data.p_form_suppy_deter_m.setProps({
                            u_division: {
                                //事业部or组织
                                value: datas.org_phid,
                                label: datas.org_name,
                            },
                            u_regional_center: {
                                //区域中心
                                value: datas.regional_center_phid,
                                label: datas.regional_center_name,
                            },
                            u_product_line: {
                                //产品线
                                value: datas.midwife_phid,
                                label: datas.midwife_name,
                            },
                        });
                    });
                }
            );
        }
    }

    function provinceMFilter(data) {
        console.log(data.u_province, "获取值");
        if (!data.u_province.value) {
            return;
        }
        $NG.updateUI((updater, state) => {
            updater.fieldSetForm.p_form_suppy_deter_m.u_city.setProps({
                clientSqlFilter: {
                    provinceno: $NG
                        .getCmpApi("p_form_suppy_deter_m")
                        .getItem("u_province")
                        .getValue(),
                },
            });
        });
    }
    //监听集采表格
    useUpdateRows(({ args, table }) => {
        const rows = args[0];
        console.log(rows,'record111');
        rows.forEach((record, index) => {
            $NG.execServer(
                "getAutoType",
                { phid: record.u_wzxl },
                function (res) {
                    try {
                        const datas = JSON.parse(res.data)[0].extendObjects;
                        console.log(datas, "获取值datas");
                        
                        record.u_wzzl = datas.f_phid;
                        record.u_wzzl_EXName = datas.fname;
                        record.u_wzdl = datas.g_phid;
                        record.u_wzdl_EXName = datas.gname;
                        record.u_wzxl = datas.phid;
                        record.u_wzxl_EXName = datas.name;
                        getRuleInfoTableData(record.u_wzdl, record.u_is_yc, record);
                        setTimeout(() => {
                            gridTab.refreshView();
                        }, 200);
                    } catch (error) {
                        console.log("bc薄薄搓搓")
                    }
                }
            );
            gridTab.refreshView();
        });
    }, "p_form_suppy_deter_d2");

    /**
     *@function:计算案情数量 平均值 和 总额度
     */
    function reduceTable2(rows) {
        console.log("进入reduceTable2", rows);
        let sbwztyxVal = getItemValue("u_sbwztyx");
        let AlNum = gridTab4.getRows().length; //累计案情数量
        $NG.updateState((updater) => {
            updater.data.p_form_suppy_deter_m.setProps({
                u_anpg_number: rows.length,
            });
        });
        pdFun(AlNum, sbwztyxVal);
        return rows.length;
    }
    function hasYearsPassed(inputDateStr, years) {
        //封装年限判断函数
        // 将输入日期字符串转换为 Date 对象
        const inputDate = new Date(inputDateStr);

        // 获取当前日期
        const currentDate = new Date();

        // 计算指定年限之前的日期
        const pastDate = new Date();
        pastDate.setFullYear(currentDate.getFullYear() - years);

        // 比较日期
        if (inputDate <= pastDate) {
            console.log(`输入的日期距离今天已经过去了${years}年或更久`);
            return true;
        } else {
            console.log(`输入的日期距离今天不足${years}年`);
            return false;
        }
    }

    function getRuleInfoTableData(phid, dlyc, record) {
        console.log(phid, "phid1111",dlyc,'dlyc1111');
        let registeredPrice = getItemValue("u_register_capital");
        let createTime = getItemValue("u_cl_data");
        console.log(
            registeredPrice,
            createTime,
            "registeredPrice, createTimesuccess"
        );

        if (registeredPrice == 0) {
            $NG.alert("注册资本不为0");  
            record.u_is_yc = null;
            record.u_is_yc_EXName = null;
            gridTab.refreshView();
            return;
        }
        if (registeredPrice && createTime) {
            if (phid && dlyc) {
                $NG.execServer("getRuleInfoTableData", {}, function (res) {
                    // 数据数组
                    console.log(res);
                    
                    let data = JSON.parse(res.data);
                    console.log(data);
                    
                    // 提取 extendObjects 项为数组
                    const extractExtendObjects = (data) => {
                        return data.map((item) => item.extendObjects);
                    };
                    // 根据 u_pl 查找对应的 extendObjects 项c
                    const findByUPl = (data, targetUPl) => {
                        console.log(targetUPl);
                        
                        const extendObjectsArray = extractExtendObjects(data);
                        return extendObjectsArray.find(
                            (obj) => obj.u_pl == targetUPl && obj.u_dlyc == dlyc
                        );
                    };
                    const result = findByUPl(data, phid);

                    console.log(result, "resultfindByUPl");

                    RuleCheck(result, registeredPrice, createTime, record);
                    return result;
                    //帮助字段赋值
                });
            }
            // else if (phid && dlyc == null) {
            // 	$NG.alert("请选择对应的供应商类型和和商品来源,原厂/代理");
            // 	record.u_is_yc = null;
            // 	record.u_is_yc_EXName = null;
            // 	gridTab.updateRow(record);
            // 	gridTab.refreshView();
            // }
        } else if (registeredPrice == null || createTime == null) {
            // $NG.alert("注册资金与成立时间有误或者值为空请手动填写或者录入"); // TODO
            issueMap.yc = "注册资金与成立时间有误或者值为空请手动填写或者录入"
            // record.u_is_yc = null;
            // record.u_is_yc_EXName = null;
            gridTab.refreshView();
        }
    }

    const RuleCheck = (Rule, registeredPrice, createTime, record) => {
        console.log(record, "record,RuleCheck");
        console.log(Rule);
        
        console.log(createTime, "createTime");
        //规则校验函数
        console.log(Rule, !Array.isArray(Rule), "!Array.isArray(Rule)");
        // if (Rule == undefined) {
        //     $NG.alert("该供应商类型和商品来源没有对应的规则");
        //     record.u_is_yc = null;
        //     record.u_is_yc_EXName = null;
        //     gridTab.updateRow(record);
        //     gridTab.refreshView();
        //     return;
        // }

        if (!Array.isArray(Rule)) {
            let YearFlag = hasYearsPassed(createTime, Rule.u_clnx);

            let PriceFlag = meetsRequirementInTenThousand(
                registeredPrice,
                Rule.u_zczj
            );
            if (YearFlag == true && PriceFlag == true) {
                // $NG.alert("符合要求");
                return;
            }

            if (YearFlag == false && PriceFlag == true) {
                // $NG.alert("不符合年限(" + Rule.u_clnx + "年)要求");// TODO
                issueMap.year = "不符合年限(" + Rule.u_clnx + "年)要求"
            } else if (YearFlag == false && PriceFlag == false) {
                // $NG.alert(
                //     "不符合年限(" +
                //     Rule.u_clnx +
                //     "年)与注册资金(" +
                //     Rule.u_zczj +
                //     "万)要求"
                // );
                issueMap.year = "不符合年限(" +
                    Rule.u_clnx +
                    "年)与注册资金(" +
                    Rule.u_zczj +
                    "万)要求"
            } else if (YearFlag == true && PriceFlag == false) {
                issueMap.year = "不符合注册资金(" + Rule.u_zczj + "万)要求"
            }
            // record.u_is_yc = null;
            // record.u_is_yc_EXName = null;
            gridTab.updateRow(record);
            gridTab.refreshView();
        }
        gridTab.refreshView();
    };

    function meetsRequirementInTenThousand(value, requirementInWan) {
        // 将值转化为“万”为单位
        const valueInWan = value / 10000;

        // 判断是否达到要求
        if (valueInWan >= requirementInWan) {
            console.log(`数字 ${valueInWan} 万达到要求（≥ ${requirementInWan} 万）`);
            return true;
        } else {
            console.log(
                `数字 ${valueInWan} 万未达到要求（< ${requirementInWan} 万）`
            );
            return false;
        }
    }
    function pdFun(AlNum, sbwztyxVal) {
        //判断是否符合要求
        function SbwztyxFlag() {
            if (sbwztyxVal == 1) {
                return {
                    Flag: AlNum >= 3 ? true : false,
                    msg: "通用集成产品所需案例数量少于3条",
                };
            } else if (sbwztyxVal == 2) {
                return {
                    Flag: AlNum >= 2 ? true : false,
                    msg: "专用集成产品所需案例数量至少2条",
                };
            } else if (sbwztyxVal == 3) {
                return {
                    Flag: AlNum >= 2 ? true : false,
                    msg: "新扩展业务涉及设备行业应用所需案例数量至少2条",
                };
            }
        }
        Flag1 = SbwztyxFlag();
    }
    /**
     *@function:时间校验规则函数
     */

    function isWithinYears(inputDateStr, years) {
        // 将输入日期字符串转换为 Date 对象
        const inputDate = new Date(inputDateStr);

        // 获取当前日期
        const currentDate = new Date();

        // 计算指定年限之前的日期
        const pastDate = new Date();
        pastDate.setFullYear(currentDate.getFullYear() - years);

        // 比较日期
        if (inputDate > pastDate && inputDate <= currentDate) {
            console.log(`输入的日期距离今天在${years}年之内`);
            return true;
        } else {
            console.log(`输入的日期距离今天不在${years}年之内`);
            return false;
        }
    }
    // 按钮点击前事件
    useBeforeClick(function ({ args }) {
        var gridTab4 = $NG.getCmpApi("p_form_suppy_deter_d4"); // 获取tab页数据
        console.log(`Flag1`,Flag1);
        if (!Flag1.Flag) {
            // $NG.alert(Flag1.msg);
            issueMap.num = Flag1.msg
        //     return false;
        }
        let str = ''
        for(let key in issueMap){
            str += issueMap[key] +">>><<<"
        }
        const rows = []
        gridTab4.forEach((row,index)=>{
            if (row.u_cnt_dt) {
                let timeFlag = isWithinYears(row?.u_cnt_dt, 2);
                if (!timeFlag) {
                    rows.push(index+1)
                }
            }
        })
        if(rows.length != 0){
            str += `案例情况明细第${rows.join(",")} 行，时间校验不通过不在两年以内`
        }
        mstform.getItem("u_bfhx").setValue(str)
    
        // // 取消向下执行
        return true;
    }, "save");
});
